package cn.rongdao.jrkabao.ui.loan.adapter.viewholder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mifengkong.frtools.ui.adapter.recyclerview.FRBaseRecyclerViewHolder;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.loan.MultiPushBean;
import cn.rongdao.jrkabao.ui.loan.adapter.listener.MutliPustitemClickListener;
import cn.rongdao.jrkabao.util.CommonUtil;

/**
 * Created by jack on 17/5/16
 */

public class MultiPushRepaymentViewHolder extends FRBaseRecyclerViewHolder<MultiPushBean.ProductListBean> {


    private final ImageView mIcon;
    private final TextView mName;
    private final TextView mDesc;
    private final TextView mOrderDetail;
    private final TextView mStage;
    private final TextView mAmount;
    private final TextView mRepayDetail;
    private final TextView mRepayWay;
    private final View mShadow;
    private final TextView mRepayCurrentNumber;
    private final TextView mRepayTotalNumber;
    private MutliPustitemClickListener mutliPustitemClickListener;

    public MultiPushRepaymentViewHolder(View itemView, MutliPustitemClickListener clickListener) {

        super(itemView);
        this.mutliPustitemClickListener = clickListener;
        mIcon = findView(R.id.impr_icon);
        mName = findView(R.id.impr_name);
        mDesc = findView(R.id.impr_desc);
        mOrderDetail = findView(R.id.impr_detail);
        mAmount = findView(R.id.impr_amount);
        mStage = findView(R.id.impr_stage);
        mRepayCurrentNumber = findView(R.id.impr_repay_current_number);
        mRepayTotalNumber = findView(R.id.impr_repay_total_number);
        mRepayWay = findView(R.id.impr_repay_way);
        mRepayDetail = findView(R.id.impr_repay_detail);
        mShadow = findView(R.id.impr_center_view);
    }


    @Override
    protected void onItemDataUpdated(final MultiPushBean.ProductListBean productListBean) {
        Glide.with(getContext()).load(productListBean.getOrg_pic()).into(mIcon);

        mName.setText(productListBean.getOrg_name());
        mDesc.setText(CommonUtil.timeStamp2Date(String.valueOf(productListBean.getCreate_time())));
        mAmount.setText(productListBean.getAmount());
        mStage.setText(productListBean.getStages());
        mRepayCurrentNumber.setText(productListBean.getCurrent());
        mRepayTotalNumber.setText(TextUtils.concat("/", productListBean.getTotal(), "期"));

        mShadow.setVisibility(productListBean.isShowCenterShaow() ? View.VISIBLE : View.GONE);

        if (mutliPustitemClickListener != null) {
            mOrderDetail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mutliPustitemClickListener.setItemOrderDetailClickListener(productListBean.getLink());
                }
            });

            mRepayDetail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mutliPustitemClickListener.setItemOrderRepayMentDetailClickListener(productListBean.getReturn_plan());
                }
            });

            mRepayWay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mutliPustitemClickListener.setItemOrderRepayWayClickListener(productListBean.getReturn_way());
                }
            });
        }
    }
}